#pragma once

#include "common.h"
#include "../socketcore/IOCPS.h"
#include "../DBJet/DBSvr.h"
#include "../dldmsg/msg2.h"

#include "./MsgCore.h"

class _DLL CServer:public IServer,public IMsgHandle
{
public:
	CServer();
	//CServer(CDBSvr*db);
	virtual ~CServer();
public:
	virtual void OnRecvData(CClientContext *client,const LPVOID data,size_t size);

	bool SendData(CClientContext *client,const LPVOID data,size_t size)
	{
		return Send(client,data,size);
	}

	template <class T>
		bool SendMsg(CClientContext *client,NetPacket<T> msg)
	{
		return Send(client,&msg,sizeof(msg));
	}

	virtual bool OnConnectionCreate(CClientContext *client);
	virtual void OnConnectionClosed(CClientContext *client);

	CDBSvr * GetDBConnect();
public:
	virtual void SendMsg(LPVOID data,size_t len,int table = 0,BYTE station = 0);
	virtual void BroadcastMsg(LPVOID data,size_t len,int table = 0,BYTE station = 0);
public:
	virtual bool StartServer(int port,char*dbCmd);
	virtual void StopServer();
private:
	CDBSvr * m_db;
	CMsgCore * m_msgCore;
	int m_port;
public:
	static int	m_gServerID;
	static int	m_gTableCounts;
	static int	m_gMaxUserCounts;
};